import request from "@/utils/request";

const AUTH_BASE_URL = "/api/v1/auth";
// const AUTH_BASE_URL = "";



const VITE_APP_API_URL = 'https://shanxisyc.com/index';
const VITE_APP_API_OUT_URL = 'https://shanxisyc.com';

const AuthAPI = {
    /** 登录 接口*/
    login(data: LoginData) {
        const formData = new FormData();
        formData.append("username", data.username);
        formData.append("password", data.password);
        formData.append("type", data.type);
        // formData.append("captchaKey", data.captchaKey);
        // formData.append("captchaCode", data.captchaCode);
        return request<any, LoginResult>({
            url: `${VITE_APP_API_URL}/login`,
            // url: `${AUTH_BASE_URL}/login`,
            method: "post",
            data: formData,
            headers: {
                "Content-Type": "multipart/form-data",
            },
        });
    },

    /** 注销 接口*/
    logout() {
        const formData = new FormData();
        formData.append("type", 'web-admin');
        return request({
            url: `${VITE_APP_API_OUT_URL}/index/logout`,
            method: "post",
            data: formData,
            headers: {
                "Content-Type": "multipart/form-data",
            },
        });
    },

    /** 获取验证码 接口*/
    getCaptcha() {
        return request<any, CaptchaResult>({
            url: `${AUTH_BASE_URL}/captcha`,
            method: "get",
        });
    },
};

export default AuthAPI;

/** 登录请求参数 */
export interface LoginData {
    /** 用户名 */
    username: string;
    /** 密码 */
    password: string;
    type: string;
    /** 验证码缓存key */
    // captchaKey: string;
    // /** 验证码 */
    // captchaCode: string;
}

/** 登录响应 */
export interface LoginResult {
    /** 访问token */
    accessToken?: string;
    /** 过期时间(单位：毫秒) */
    expires?: number;
    /** 刷新token */
    refreshToken?: string;
    /** token 类型 */
    tokenType?: string;
}

/** 验证码响应 */
export interface CaptchaResult {
    /** 验证码缓存key */
    captchaKey: string;
    /** 验证码图片Base64字符串 */
    captchaBase64: string;
}
